import Vue from 'vue';
import Vuex from 'vuex';


import getters from './getters.js';

//读取所有路由文件
const requireModules = require.context('@/store', false, /\.js$/);

const getFilePath = function (value) {
    value = value.replace(/\.\//, "");
    value = value.replace(/\.js/, "");
    return value;
}

let storeObject = {};
//遍历循环路由文件
requireModules.keys().forEach(file => {
    let nameInfo = getFilePath(file);
    if (['index', 'getters'].indexOf(nameInfo) === -1) {
        //获取组建信息
        let component = requireModules(file);
        storeObject[nameInfo] = component.default;
    }
})

Vue.use(Vuex);

export default new Vuex.Store({
    modules: storeObject,
    state: {},
    mutations: {},
    actions: {},
    getters: getters
});
